import syRequest from "@/service"

const rootUrl = "/studyRoom"

interface IreleaseStudyRoom {
  name: string
  describes: string
  facilities: string
  image: string
  people_ceiling: number
  charge: string
  latitude: any
  longitude: any
}
// 发布自习室
export function releaseStudyRoom(data: IreleaseStudyRoom) {
  return syRequest.post({
    url: `${rootUrl}/releaseStudyRoom`,
    data
  })
}

// 获取自习室
export function getStudyRoom(longitude, latitude, limit, offset) {
  return syRequest.get({
    url: rootUrl + "/getStudyRoom",
    params: {
      longitude,
      latitude,
      limit,
      offset
    }
  })
}

/**
 *
 * @param keyWord 模糊查询的字段
 * @param limit 限制
 * @param offset 偏移
 * @returns
 */
export function likeSearchStudyRoom(keyWord, limit, offset) {
  return syRequest.get({
    url: rootUrl + `/likeSearchStudyRoom/${keyWord}`,
    params: {
      limit,
      offset
    }
  })
}

/**
 *
 * 预约自习室
 * @returns
 */
interface IAppointmentStudyRoom {
  room_uid: number
  room_id: number
  reservation_date: string
  start_time: string
  end_time: string
}
export function appointmentStudyRoom(data: IAppointmentStudyRoom) {
  return syRequest.post({
    url: rootUrl + `/appointmentStudyRoom`,
    data
  })
}

/**
 * 获取自己的预约
 * @param limit
 * @param offset
 * @returns
 */
export function getAppointment(limit, offset, isSuccess = false) {
  return syRequest.get({
    url: rootUrl + `/getAppointment`,
    params: {
      limit,
      offset,
      isSuccess
    }
  })
}

/**
 * 添加用户权限
 *  1:Common 普通
 *  2:Member 会员
 *  3:Admin 管理
 */
export function addAuthority(authId) {
  return syRequest.patch({
    url: `/users/addAuthority/${authId}`
  })
}

/**
 * 评价自习室
 */
interface IEvaluateStudyRoom {
  room_uid: number
  room_id: number
  rate: number
  feedback: string
  attitude: string
  consumption: number
}
export function evaluateStudyRoom(data: IEvaluateStudyRoom) {
  return syRequest.post({
    url: rootUrl + `/evaluateStudyRoom`,
    data
  })
}

/**
 * 获取发布自习室的预约情况
 * @param limit
 * @param offset
 * @returns
 */
export function getAppointmentByStudyRoom(limit, offset) {
  return syRequest.get({
    url: rootUrl + `/getAppointmentByStudyRoom`,
    params: {
      limit,
      offset
    }
  })
}

/**
 * 审核预约
 * @param reservationId 预约id
 * @param audit_id 3：待审核 2：审核成功 1：审核失败
 * @returns
 */
export function auditReservation(reservationId, audit_id) {
  return syRequest.patch({
    url: rootUrl + `/auditReservation`,
    params: {
      reservationId,
      audit_id
    }
  })
}

/**
 * 更新预约人数
 * @param room_id 预约id
 * @param state 1：增加 -1：减少
 * @returns
 */
export function updateReservePerson(room_id, state) {
  return syRequest.patch({
    url: rootUrl + `/updateReservePerson`,
    params: {
      room_id,
      state
    }
  })
}

/**
 *
 * 获取预约时间段
 */
export function getAppointmentTimeQuantum() {
  return syRequest.get({
    url: rootUrl + `/getAppointmentTimeQuantum`
  })
}

/**
 *
 * 获取营收
 */
export function getRevenue() {
  return syRequest.get({
    url: rootUrl + `/getRevenue`
  })
}
